<?php
//用户修改头像
if(isset($_POST['submit']))
{
    if(isset($_FILES)){
        $submit=$_POST['submit'];
        $fname=$_FILES["file"]["name"];//上传文件名
        $fname = iconv('utf-8','gb2312',$_FILES["file"]["name"]);
        $ftype=$_FILES["file"]["type"];
        $lname=substr($fname,strpos($fname,"."));//获取文件后缀名
        /*  设置上传文件类型   */
        $flag=0;
        switch($lname){
            case ".jpg" :
                $flag=1;
                break;
            case ".gif":
                $flag=1;
                break;
            case ".jpeg":
                $flag=1;
                break;
            case ".png":
                $flag=1;
                break;
        };
        switch ($ftype){
            case "image/jpg":
                $flag++;
                break;
            case "image/gif":
                $flag++;
                break;
            case "image/jpeg":
                $flag++;
                break;
            case "image/png":
                $flag++;
                break;
        };
        if($submit=="确认提交")
        {
            if($flag==2) {
                if (file_exists("tem/" . $fname)) {
                    echo $fname . " 文件已经存在 ";
                } else {
                    $fload = move_uploaded_file($_FILES["file"]["tmp_name"], "public/images/" . $fname);
                    if ($fload) {
                        $fileurl="images/".$fname;
                        $con = mysqli_connect("localhost","root","root","userinfo");
                        $sq="update usersinfo set imgurl= '$fileurl' WHERE uid = '$uid'";
                        $sq1=mysqli_query($con,$sq);
                        mysqli_close($con);
                        /*include_once "model/Mydatabase.class.php";
                        $odb=new mydb();
                        $sql="update usersinfo set imgurl= '$fileurl' WHERE uid = '$uid'";
                        echo $sql;
                        $odb->doupdate($sql);*/
                    } else {
                        echo "错误代码:" . $_FILES["file"]["error"];
                    }
                };
            }else{
                echo "操作失败，请重试！";
            };
        };
    };
};